#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/10/23  20:51
# @Author: 余浪人
# @email: yulangren520@gmail.com
from flask import current_app ,request
from flask_caching import Cache
class MyCache (Cache ):
    def cache_with_param (OO0OO0O000OOOOO0O ,O000OOOOO000OOOOO =None ,OO000O0O0OO0OO0OO ='view/%s',O0000O00O00O0OO0O =None ):
        def OOOOOOO00OO0O00OO ():
            with current_app .app_context ():
                OOO0OOOOO0O000OOO =OO000O0O0OO0OO0OO %request .url if '%s'in OO000O0O0OO0OO0OO else OO000O0O0OO0OO0OO
            return OOO0OOOOO0O000OOO
        return cache .cached (timeout =O000OOOOO000OOOOO ,key_prefix =OOOOOOO00OO0O00OO ,unless =O0000O00O00O0OO0O )
cache =MyCache (with_jinja2_ext =False )
class DictToObject :
    def __init__ (OO0OOO00O00OO0000 ,**O0O000OO00O00O000 ):
        OO0OOO00O00OO0000 .__dict__ .update (O0O000OO00O00O000 )
@cache .cached (timeout =(24 *(60 *60 ))*30 ,key_prefix ='sys_cache')
def sys_cache ():
    from apps .models .system_model import TL_System_Model
    O0O00O0OO00OOOO0O =TL_System_Model .query .first ()
    return O0O00O0OO00OOOO0O
@cache .cached (timeout =30 *(24 *(60 *60 )),key_prefix ='current_theme')
def current_theme ():
    from apps .models .synthesize_model import TL_ThemePush_Model
    OOOOOOO000000OOO0 =TL_ThemePush_Model .query .filter_by (is_current =1 ).first ()
    if OOOOOOO000000OOO0 :return OOOOOOO000000OOO0 .identifier
@cache .cached (timeout =(24 *(60 *60 ))*30 ,key_prefix ='redis_cache')
def redis_conf ():
    from apps .models .system_model import TL_Redis_Model
    O0OOOOOOOO00OO0OO =TL_Redis_Model .query .filter ().first ()
    return O0OOOOOOOO00OO0OO